/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Cadastro_Funcionarios.java
 *
 * Created on 27/05/2011, 19:08:14
 */

package Formularios;

import Dao.FuncionarioDao;
import DataBase.DataBase;
import Model.Funcionarios;
import javax.swing.JOptionPane;

/**
 *
 * @author Cleiviane
 */
public class Cadastro_Funcionarios extends javax.swing.JInternalFrame {

    Funcionarios funcionario;
    /** Creates new form Cadastro_Funcionarios */
    public Cadastro_Funcionarios() {
        initComponents();
        DataBase.ConectarDataBase();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        txtnome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtendereco = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtrg = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtcpf = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txttelefone = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtcontrato = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cbocargo = new javax.swing.JComboBox();
        botaoSalvar = new javax.swing.JButton();
        botaoExcluir = new javax.swing.JButton();
        botaoCancelar = new javax.swing.JButton();
        botaoNovo = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        txtnascimento = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtnaturalidade = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtemail = new javax.swing.JTextField();
        botaoAlterar = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        setTitle("Cadastro Funcionários - SISAM");
        setMinimumSize(new java.awt.Dimension(130, 33));
        setOpaque(true);
        setPreferredSize(new java.awt.Dimension(550, 380));

        jLabel3.setText("Nome:");

        jLabel4.setText("Endereço:");

        jLabel5.setText("RG:");

        txtrg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtrgActionPerformed(evt);
            }
        });

        jLabel6.setText("CPF:");

        txtcpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtcpfActionPerformed(evt);
            }
        });

        jLabel7.setText("Telefone:");

        txttelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txttelefoneActionPerformed(evt);
            }
        });

        jLabel8.setText("Email:");

        jLabel9.setText("Cargo:");

        cbocargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administador SYS", "Farmaceutico", "Recepcionista" }));

        botaoSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/salvar.jpg"))); // NOI18N
        botaoSalvar.setText("Salvar");
        botaoSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoSalvar.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoSalvar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        botaoExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/excluir.jpg"))); // NOI18N
        botaoExcluir.setText("Excluir");
        botaoExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoExcluir.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoExcluir.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoExcluirActionPerformed(evt);
            }
        });

        botaoCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/cancelar.jpg"))); // NOI18N
        botaoCancelar.setText("Cancelar");
        botaoCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoCancelar.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoCancelar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        botaoNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/novo.jpg"))); // NOI18N
        botaoNovo.setText("Novo");
        botaoNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoNovo.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoNovo.setVerifyInputWhenFocusTarget(false);
        botaoNovo.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoNovoActionPerformed(evt);
            }
        });

        jLabel10.setText("D.Nasc:");

        txtnascimento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnascimentoActionPerformed(evt);
            }
        });

        jLabel11.setText("Naturalidade:");

        txtnaturalidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnaturalidadeActionPerformed(evt);
            }
        });

        jLabel12.setText("Data Contrato:");

        botaoAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/alterar.jpg"))); // NOI18N
        botaoAlterar.setText("Alterar");
        botaoAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoAlterar.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoAlterar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarActionPerformed(evt);
            }
        });

        jLabel13.setText("Código:");

        txtCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCodigoFocusLost(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(botaoSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jLabel9)
                        .addGap(4, 4, 4)
                        .addComponent(cbocargo, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtnome, javax.swing.GroupLayout.PREFERRED_SIZE, 455, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addComponent(jLabel7)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txttelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtcontrato, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))
                            .addComponent(txtendereco, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                            .addComponent(txtemail, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtrg))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel10)
                                .addGap(4, 4, 4)
                                .addComponent(txtnascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtnaturalidade, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtcpf)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtnome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel5))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtrg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6))
                    .addComponent(txtcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel10))
                    .addComponent(txtnascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(txtnaturalidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtendereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jLabel12)
                        .addComponent(txttelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtcontrato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel9))
                    .addComponent(cbocargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void txtnascimentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnascimentoActionPerformed
		// TODO add your handling code here:
}//GEN-LAST:event_txtnascimentoActionPerformed

	private void txtrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtrgActionPerformed
		// TODO add your handling code here:
}//GEN-LAST:event_txtrgActionPerformed

	private void txtcpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcpfActionPerformed
		// TODO add your handling code here:
}//GEN-LAST:event_txtcpfActionPerformed

	private void botaoNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoNovoActionPerformed
            limpacampos();
            destravacampos();
            txtCodigo.setEditable(true);
            txtCodigo.requestFocus();
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(false);
            botaoNovo.setEnabled(false);
            botaoSalvar.setEnabled(true);		// TODO add your handling code here:
}//GEN-LAST:event_botaoNovoActionPerformed

	private void txttelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txttelefoneActionPerformed
		// TODO add your handling code here:
}//GEN-LAST:event_txttelefoneActionPerformed

	private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed

            funcionario = new Funcionarios();
            funcionario.setCod_funcionario(Integer.parseInt(txtCodigo.getText()));
            funcionario.setNome(txtnome.getText());
            funcionario.setEndereco(txtendereco.getText());
            funcionario.setCpf(txtcpf.getText());
            funcionario.setRg(txtrg.getText());
            funcionario.setTelefone(txttelefone.getText());
            funcionario.setData_nascimento(txtnascimento.getText());
            funcionario.setEmail(txtemail.getText());
            funcionario.setNaturalidade(txtnaturalidade.getText());
            funcionario.setCargo(cbocargo.getSelectedIndex());
            funcionario.setData_contrato(txtcontrato.getText());

            if (txtCodigo.isEditable()){
               if(FuncionarioDao.inserirfuncionario(funcionario)){
                    JOptionPane.showMessageDialog(null,"funcionario Cadastrado com Sucesso");
               }else{
                    JOptionPane.showMessageDialog(null, "Nao foi possivel Salvar");
               }
                limpacampos();
                destravacampos();
                botaoAlterar.setEnabled(false);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(false);
                botaoNovo.setEnabled(true);
                botaoSalvar.setEnabled(true);

            }else{
                    FuncionarioDao.AtualizarFuncionario(funcionario);
                    travacampos();
                    botaoAlterar.setEnabled(true);
                    botaoCancelar.setEnabled(true);
                    botaoExcluir.setEnabled(true);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(false);
            }
}//GEN-LAST:event_botaoSalvarActionPerformed

	private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
          if  (txtCodigo.getText().isEmpty()){
                    botaoAlterar.setEnabled(false);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(false);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    destravacampos();
                }
            else
                {
                    botaoAlterar.setEnabled(true);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(true);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    travacampos();
                }
}//GEN-LAST:event_botaoCancelarActionPerformed

	private void botaoExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoExcluirActionPerformed
             if (funcionario == null) {
                JOptionPane.showMessageDialog(this, "Selecione um funcionário para excluir!");
                return;
            } else {
                boolean result = JOptionPane.showInternalConfirmDialog(
                        this, "Deseja realmente excluir este Funcionário?") == 0;
                if(result == true){
                    funcionario.setCod_funcionario(Integer.parseInt(txtCodigo.getText()));
                    FuncionarioDao.deleteFuncionario(funcionario);
                    limpacampos();
                    destravacampos();
                    botaoAlterar.setEnabled(false);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(false);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(true);
                 }else
                     return;
            }		// TODO add your handling code here:
}//GEN-LAST:event_botaoExcluirActionPerformed

        private void txtnaturalidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnaturalidadeActionPerformed
            // TODO add your handling code here:
        }//GEN-LAST:event_txtnaturalidadeActionPerformed

        private void botaoAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarActionPerformed
            destravacampos();
            txtCodigo.setEditable(false);
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(true);
            botaoNovo.setEnabled(false);
            botaoSalvar.setEnabled(true);            // TODO add your handling code here:
        }//GEN-LAST:event_botaoAlterarActionPerformed

        private void txtCodigoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCodigoFocusLost
          int codFuncionario = Integer.parseInt(txtCodigo.getText());
          //funcionario =  FuncionarioDao.localizarFuncionario(codFuncionario);
          if ((funcionario =  FuncionarioDao.localizarFuncionario(codFuncionario)) != null) {
                txtnome.setText(funcionario.getNome());
                txtcpf.setText(funcionario.getCpf());
                txtendereco.setText(funcionario.getEndereco());
                txtnascimento.setText(funcionario.getData_nascimento());
                txttelefone.setText(funcionario.getTelefone());
                txtemail.setText(funcionario.getEmail());
                txtrg.setText(funcionario.getRg());
                cbocargo.setSelectedIndex(funcionario.getCargo());
                txtnaturalidade.setText(funcionario.getNaturalidade());
                txtcontrato.setText(funcionario.getData_contrato());
                
                travacampos();
                botaoAlterar.setEnabled(true);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(true);
                botaoNovo.setEnabled(true);
                botaoSalvar.setEnabled(false);
          }            
        }//GEN-LAST:event_txtCodigoFocusLost


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoExcluir;
    private javax.swing.JButton botaoNovo;
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JComboBox cbocargo;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtcontrato;
    private javax.swing.JTextField txtcpf;
    private javax.swing.JTextField txtemail;
    private javax.swing.JTextField txtendereco;
    private javax.swing.JTextField txtnascimento;
    private javax.swing.JTextField txtnaturalidade;
    private javax.swing.JTextField txtnome;
    private javax.swing.JTextField txtrg;
    private javax.swing.JTextField txttelefone;
    // End of variables declaration//GEN-END:variables

    private void travacampos() {
            txtCodigo.setEditable(false);
            txtnome.setEditable(false);
            txtcpf.setEditable(false);
            txtnaturalidade.setEditable(false);
            txtemail.setEditable(false);
            txtendereco.setEditable(false);
            txtcontrato.setEditable(false);
            txtnascimento.setEditable(false);
            txttelefone.setEditable(false);
            cbocargo.setEnabled(false);
            txtrg.setEditable(false);
    }

    private void destravacampos() {
            txtCodigo.setEditable(true);
            txtnome.setEditable(true);
            txtcpf.setEditable(true);
            txtnaturalidade.setEditable(true);
            txtemail.setEditable(true);
            txtendereco.setEditable(true);
            txtcontrato.setEditable(true);
            txtnascimento.setEditable(true);
            txttelefone.setEditable(true);
            cbocargo.setEnabled(true);
            txtrg.setEditable(true);
    }

    private void limpacampos() {
                txtCodigo.setText(null);
                txtnome.setText(null);
                txtcpf.setText(null);
                txtrg.setText(null);
                txtemail.setText(null);
                txtendereco.setText(null);
                txtnaturalidade.setText(null);
                txtnascimento.setText(null);
                txttelefone.setText(null);
                txtcontrato.setText(null);
                cbocargo.setSelectedIndex(0);
    }

}
